
package com.erhirent.view;

import java.util.InputMismatchException;

import com.erhairent.tools.InputTools;

public class UserView extends View {

	RentView rent = new RentView();
	RecordView record = new RecordView();
	OrderView order = new OrderView();
	ReturnView retur = new ReturnView();
	TypeView type = new TypeView();
	UserqueryAll query = new UserqueryAll();

	@Override
	public View showView() {
		System.out.println("输入0:   退出");
		System.out.println("输入1:   进入租车订单");
		System.out.println("输入2+1:按价格降序排序 \t  2+2:按价格升序排序");
		System.out.println("输入3:   按类型搜索");
		System.out.println("输入4:   按品牌搜索");
		System.out.println("输入5:   查看所有汽车");
		System.out.println("输入6:   查看我的租车记录");
		System.out.println("输入7:   还车");
		System.out.println("输入8:   预约车");
		System.out.println("请选择:");
		return mView;
	}

	public void chooseNumber2() {

		String chooseNum;
		int i = 0;
		int j = 0;
		while (true) {
			try {
				chooseNum = InputTools.next();
				if (chooseNum.length() == 2) {
					System.out.println("没有该选项,重新输入");
					continue;
				} else if (chooseNum.length() > 2) {
					j = Integer.valueOf(chooseNum.substring(2));
				}
				break;
			} catch (InputMismatchException e) {
				System.out.println("请重新输入");
				InputTools.next();
			}
		}
		i = Integer.valueOf(chooseNum.substring(0, 1));
		switch (i) {
		case 1:
			// 租车

			rent.showView();
			showView();
			chooseNumber2();
			break;
		case 2:
			if (j == 1) {
				mcar.queryDesc();
			} else if (j == 2) {
				mcar.queryAsc();
			} else {
				System.out.println("没有该选项,重新输入:");
			}
			showView();
			chooseNumber2();
			break;
		case 3:
			// 类型排序 查完回到主界面
			type.showView();
			showView();
			chooseNumber2();
			break;
		case 4:
			// 品牌排序 查完回到主界面
			mcar.querybrand();
			System.out.println("输入你想要查询的汽车品牌编号:");
			int m = InputTools.nextInt();
			mcar.brandquery(m);

			showView();
			chooseNumber2();
			break;
		case 5:
			// 查看所有汽车
			query.showView();

			showView();
			chooseNumber2();
			break;
		case 6:
			// 租车记录
			record.showView();

			showView();
			chooseNumber2();
			break;
		case 7:
			// 还指定车
			retur.showView();
			showView();
			chooseNumber2();
			break;
		case 8:
			// 预约车 添加字段 已预约的 不可预约
			order.showView();

			showView();
			chooseNumber2();
			break;
		case 0:
			System.out.println("欢迎下次租车");
			break;
		default:
			System.out.println("重新选择:");
			showView();
			chooseNumber2();
			break;
		}

	}

}
